package com.rin.service;

import com.rin.util.ParseEntity;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;

/**
 * @author RinMi
 * @since 2023/6/13
 */

@Service
public class SelectService extends BaseService {

    public Object select(Object entity, String entityId) {
        if (checkId(entity, entityId) == 0) {
            return null;
        }
        String destination = createDestination(entity.getClass(), entityId);
        InputStream inputStream = download(destination);
        return ParseEntity.parseEntity(inputStream, entity.getClass());
    }

    public List<Object> selectBatch(Object entity) {
        //存储id列表
        List<String> idList = selectIdList(entity);
        //存储查询结果
        List<Object> objectList = new LinkedList<>();
        for (String id : idList) {
            if (checkId(entity, id) == 0) {
                continue;
            }
            objectList.add(select(entity, id));
        }
        return objectList;
    }
}
